﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Admin_LienHe_TTLienHe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            if (Request.QueryString["Id"] != null)
            {
                try
                {
                    int s = Convert.ToInt32(Request.QueryString["Id"].ToString());
                    using (LienHe ent_LienHe = DataRepository.LienHeProvider.GetById(s))
                    {
                        if (ent_LienHe != null)
                        {
                            lbHoTen.Text = ent_LienHe.HoTen;
                            lbThanhPho.Text = ent_LienHe.ThanhPho;
                            lbEmail.Text = ent_LienHe.ThuDienTu;
                            lbDienThoai.Text = ent_LienHe.DienThoai;
                            lbNgayGui.Text = Convert.ToDateTime(ent_LienHe.NgayCapNhat).ToString("dd/MM/yyyy");
                            lbYeuCauChiTiet.Text = GetDiemDen(ent_LienHe.IdDiemDen);
                            lbGiaTour.Text = GetGiaTour(ent_LienHe.IdGiaTour);
                            lbYeuCau.Text = ent_LienHe.YeuCau;
                            string query;
                            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["netTiersConnectionString"].ConnectionString);
                            conn.Open();
                            query = "UPDATE LienHe SET TrangThai = 1 where Id = '" + Request.QueryString["Id"].ToString() + "'";
                            SqlCommand sqlCommand = new SqlCommand();
                            sqlCommand.Connection = conn;
                            sqlCommand.CommandText = query;
                            sqlCommand.ExecuteNonQuery();
                            conn.Close();
                            // end update luot xem        
                        }
                    }


                }
                catch (Exception ex)
                {
                    Common.WriteLog("TTLienHe.aspx.cs", "Page_Load()", ex.ToString());
                    string strScript = "<script>parent.parent.GB_hide();</script>";
                    this.RegisterClientScriptBlock("strScript", strScript);
                }
            }
        }
    }
    public string GetDiemDen(object Id)
    {
        int s = Convert.ToInt32(Id.ToString());
        NoiDen ent_NoiDen = DataRepository.NoiDenProvider.GetById(s);
        return ent_NoiDen.TenNoiDen;
    }
    public string GetGiaTour(object Id)
    {
        int s = Convert.ToInt32(Id.ToString());
        GiaTour ent_GiaTour = DataRepository.GiaTourProvider.GetById(s);
        return ent_GiaTour.SoTien;
    }
}